package com.genloong.flycloud.filecenter.message;


import lombok.extern.java.Log;
import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.UnsupportedEncodingException;

@Log
@Service("MessageServer")
public class MessageServer {
    @Autowired
    AmqpTemplate amqpTemplate;
    @Autowired
    AmqpAdmin amqpAdmin;

    /**
     * @param exchange 路由
     * @param routingKey 路由key
     * @param msg 消息
     */
    public void send(String exchange, String routingKey,String msg){
        Message message = null;
        try {
            message = new Message(msg.getBytes("UTF-8"),new MessageProperties());
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        amqpTemplate.send(exchange,routingKey, message);
        log.info("exchange:"+exchange+"\nroutingKey:"+routingKey+"\n发送消息："+msg);
    }

}
